<style>
    #formchannels{padding: 10px 5px 10px 10px;}
    #formchannels input,#formorder select{margin: 5px auto;}
    #formchannels button{border: 1px solid transparent;background-color: #5bc0de;color: #fff;border-radius: 3px;}
    
    .page{border-top: 1px solid #E0E0E0;padding: 5px;}
    .page .page_count{padding-top: 5px;}
    .page .page_count label{display: inline-block;line-height: 30px;font-weight: normal;float: left;}
    .page .page_count .paginate_button{
        margin: 0 5px;
        float: left;
        background-color: #D5D5D5;
        padding: 5px 12px;
        color: #7d7d7d;
        border-radius: 3px;
    }
    .page .page_count .paginate_button:hover{
        background-color: #89affc;
        color: #fff;
    }
    .page .page_count .paginate_active{
        margin: 0 5px;
        float: left;
        padding: 5px 12px;
        color: #fff;
        background-color: #89affc;
        border-radius: 3px;
    }
    
    .cz_clik a{display: inline-block;background: #89affc;color: #fff;padding: 3px 10px;border-radius: 3px;min-width: 76px;text-align: center;}
    .cz_clik a:hover{background: #89bffc;}
    
</style>
<section class="vbox">
    <section class="scrollable padder">
        <ul class="breadcrumb no-border no-radius b-b b-light pull-in">
            <li><a href="#"><i class="fa fa-home"></i>分销渠道管理中心</a></li>
            <li><a href="#">渠道管理</a></li>
            <li><a href="#">渠道列表</a></li>
        </ul>
        <div class="m-b-md">
            <h3 class="m-b-none"><span style="float:right;"><a href="#"></a></span>渠道列表</h3>
        </div>
        <section class="panel panel-default">
            <header class="panel-heading">
                <i data-title="ajax to load the data." data-placement="bottom" data-toggle="tooltip" class="fa fa-info-sign text-muted" data-original-title="" title=""></i> 
                <b>渠道列表</b>
            </header>
			<div>
				<form action="" method="get" id="formchannels">
					渠道名称：<input type="text" name="keyName" value="<?=$keyName?>"/>
					<button>搜索</button>
					<a href="<?=$this->url("channels/index")?>" style="font-size: 12px;color: red;margin-left: 10px;">显示全部</a>
				</form>
			</div>
            <table data-ride="datatables" class="table table-striped m-b-none dataTable" id="DataTables_Table_0" >
            <thead>
                <tr role="row">
                    <th>序号</th>
                    <th>渠道名称</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
            <?
            if(!empty($re)){
                foreach($re as $k=>$v){?>
                <tr role="row">
                    <td><?=$k+1?></td>
                    <td><?=$v['title']?></td>
                    <?
                    $status=1;
                    $color="red";
                    $htmla="已关闭";
                    $backcolor = "#89affc";
                    $html="开启";
                    $id=0;
                    if($chR){
                        foreach($chR as $key=>$val){
                            if($v['id']==$val['chId']&&$val['status']==1){
                                $status=0;
                                $color="green";
                                $htmla="已开启";
                    			$backcolor = "#FC8989";
                                $html="关闭";
                            }
                            if($v['id']==$val['chId']){
                                $id=$val['id'];
                            }
                        }
                    }
                    ?>
                    <td style="color: <?=$color?>;"><?=$htmla?></td>
                    <td class="cz_clik">
                        <a href="javascript:;" class="show_shadefrist" style="background: <?=$backcolor?>;" onclick="status('<?=$status?>','<?=$v['id']?>','<?=$id?>')" ><?=$html?></a>
                    </td>
                </tr>
                <?}
            }else{?>
                <tr><td colspan="10">没有相关内容</td></tr>
            <?}
            ?>
            </tbody>
            </table>
            <div class="page">
                <?=$pageHtml?>
            </div>
        </section>
    </section>
</section>
<a href="#" class="hide nav-off-screen-block" data-toggle="class:nav-off-screen" data-target="#nav"></a>
<script type="text/javascript">
function status(status,chId,id){
    //if(confirm("确定该操作？")){
        $.ajax({
    		type:'POST',
    		url:'<?=$this->url("channels/status")?>',
    		data:'id='+id+'&status='+status+'&chId='+chId,
    		dataType:'json',
    		success:function(r){
    		    if(r.state==1){
    		      pub_alert_success(r.html,2000);
    		      setTimeout(function(){window.location.reload();},2000);
    		    }else if(r.state==0){
    		        pub_alert_error(r.html,2000);
    		    }
    		},
            error:function(){
                pub_alert_error("ajax出现错误",2000);
            }
    	});
    //}
}
</script>